package com.example.emqx.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class JacksonConfig {
    @Bean
    public ObjectMapper objectMapper() {
        log.info("objectMapper------------------");
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); // 确保日期被序列化为时间戳
        return mapper;
    }
//    @Bean
//    public ObjectMapper objectMapper2() {
//        ObjectMapper mapper = new ObjectMapper();
//        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
//
//        SimpleModule module = new SimpleModule();
//        module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
//            @Override
//            public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
//                long timestamp = p.getLongValue();
//                return new Date(timestamp);
//            }
//        });
//        mapper.registerModule(module);
//
//        return mapper;
//    }
}
